package com.ssy.lingxi.settle.accounts.model.constant;

import com.ssy.lingxi.common.language.LanguageHolder;

import java.util.Arrays;

/**
 * 请款单类型
 * @author Houpengfei
 * @date 2021/12/14
 * @version 2.0.0
 */
public enum ApplyAmountTypeEnum {

    /**
     * 物料对账单
     */
    MATERIAL(1, "物料对账单", 0),

    /**
     * 采购询价合同
     */
    ENQUIRY(9, "采购询价合同", 1),

    /**
     * 采购招标合同
     */
    TENDER(11, "采购招标合同", 2),

    /**
     * 采购竞价合同
     */
    BIDDING(10, "采购竞价合同", 3),

    /**
     * 采购请购单
     */
    REQUISITION(12, "采购请购单", 0);

    private final Integer code;
    private final String message;
    private final Integer contractCode;

    ApplyAmountTypeEnum(Integer code, String message, Integer contractCode) {
        this.code = code;
        this.message = message;
        this.contractCode = contractCode;
    }

    public Integer getCode() {
        return code;
    }

    public String getMessage() {
        return LanguageHolder.getName(this.getDeclaringClass(), this.getCode());
    }

    public Integer getContractCode() {return contractCode;}

    /**
     * 根据外部状态枚举值获得外部状态名称
     * @param code 外部状态枚举值
     * @return 外部状态名称
     */
    public static String getNameByCode(Integer code) {
        ApplyAmountTypeEnum statusEnum = Arrays.stream(ApplyAmountTypeEnum.values()).filter(e -> e.getCode().equals(code)).findFirst().orElse(null);
        return statusEnum == null ? "--" : statusEnum.getMessage();
    }

    public static Integer getContractCodeByCode(Integer code) {
        return Arrays.stream(ApplyAmountTypeEnum.values()).filter(e -> e.getCode().equals(code)).findFirst().map(ApplyAmountTypeEnum::getContractCode).orElse(0);
    }

}
